package cn.iocoder.yudao.module.controller;

import cn.iocoder.yudao.module.VO.StudentVo;
import cn.iocoder.yudao.module.pojo.Score;
import cn.iocoder.yudao.module.pojo.Student;
import cn.iocoder.yudao.module.service.StudentService;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.security.PermitAll;
import java.util.List;

@RestController
@Slf4j
@Tag(name="学生信息管理")
@RequestMapping("/admin-api/edu/Student")
public class StudentController {
    @Autowired
    private StudentService studentService;

    @PermitAll
    @PostMapping("addStudent")
    @Operation(summary = "添加学生基本信息")
    public CommonResult addStudent(@RequestBody StudentVo student) {
        studentService.saveStudent(student);
        return CommonResult.success("true");
    }
    @PermitAll
    @PutMapping("updateStudent")
    @Operation(summary = "更改学生基本信息")
    public CommonResult updateStudent(@RequestBody StudentVo student) {
        studentService.updateStudent(student);
        return CommonResult.success("true");
    }
    @PermitAll
    @DeleteMapping("deleteStudent")
    @Operation(summary = "删除学生基本信息")
    public CommonResult deleteStudent(@RequestBody StudentVo student) {
        studentService.deleteStudentById(student.getId());
        return CommonResult.success("true");
    }
    @PermitAll
    @GetMapping("getStudent")
    @Operation(summary = "获取学生基本信息")
    public CommonResult<Student> getStudent(Long id) {
        Student student = studentService.getStudentById(id);
        return CommonResult.success(student);
    }

    @PermitAll
    @GetMapping("getScoreListByStudentId")
    @Operation(summary = "根据学生Id查询学生Score")
    public CommonResult<List<Score>> getScoreListByStudentId(Long id) {
        //Long id = student.getId();
        List<Score> studentScoreByStudentId = studentService.getStudentScoreByStudentId(id);
        return CommonResult.success(studentScoreByStudentId);

    }
}
